package com.ts.api.common.redis;

import com.gitee.apanlh.util.base.StringUtils;
import com.gitee.apanlh.util.cache.redis.RedisKeyBuilder;
import com.gitee.apanlh.util.cache.redis.api.RedisString;
import org.springframework.stereotype.Component;

/**
 *  API分发相关key
 *  撞库唯一id流程
 *  进件申请成功流程
 *
 *  @author Pan
 */
@Component
public class ApiMatchRedisKey {

    /** 下游-我方接入/对方接入，保存拓展字段 */
    public static final RedisString DOWNSTREAM_EXTEND = RedisKeyBuilder.builder().withKeys("downstream_api_http_extend").buildString();
    /** API渠道-上游-我方接入/对方接入，保存撞库时唯一id字段 */
    public static final RedisString API_CHANNEL_DATA_EXCHANGE_REQ_ID = RedisKeyBuilder.builder().withKeys("api_channel_data_exchange_req_id").buildString();
    /** API渠道-上游-向上游进件申请成功时候保存的流程 */
    public static final RedisString API_CHANNEL_APPLY_NOTICE_FLOW = RedisKeyBuilder.builder().withKeys("api_channel_apply_notice_flow").buildString();

    /**
     *  获取成功回调进件流程Key
     *
     *  @param  apiClientId     api客户端id
     *  @param  productPlanId   主体计划id
     *  @param  phoneMd5        手机号md5
     *  @return
     */
    public static String getApplyNoticeFlowKey(String apiClientId, Long productPlanId, String phoneMd5) {
        return StringUtils.format("{}_{}_{}", apiClientId, productPlanId, phoneMd5);
    }

    /**
     *  获取唯一编号
     *
     *  @param  reqId     请求id
     *  @param  phoneMd5  手机号MD5
     *  @return String
     */
    public static String getKey(String reqId, String phoneMd5) {
        return StringUtils.format("{}_{}", reqId, phoneMd5);
    }

    /**
     *  创建撞库保存唯一id根据phoneMd5
     *
     *  @return String
     */
    public static String getDataExchangeUniqueIdByPhoneMd5(Long productId, Long productPlanId, String phoneMd5) {
        return StringUtils.format("{}_{}_{}", productId, productPlanId, phoneMd5);
    }

    /**
     *  创建撞库保存唯一id根据applyId
     *
     *  @return String
     */
    public static String getDataExchangeUniqueIdByApplyId(Long productId, Long productPlanId, String applyId) {
        return StringUtils.format("{}_{}_{}", productId, productPlanId, applyId);
    }
}
